package com.yu.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yu.crm.domain.pojo.Region;
import com.yu.crm.domain.pojo.Station;
import com.yu.crm.service.impl.GateService;
import com.yu.crm.service.impl.RegionService;
import com.yxzz.common.helper.valid.ValidatorHelpers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zds
 * @since 2021-03-12
 */
@Api(tags = "区域管理")
@RestController
@RequestMapping("/region")
public class RegionController {

    @Autowired
    private RegionService regionService;

    @ApiOperation("根据id批量删除")
    @DeleteMapping("/remove-batch-by-id")
    public void removeBatchById(@RequestParam("ids") String ids){
        regionService.deleteByIds(ids);
    }

//    @ApiOperation("根据id删除车站")
//    @DeleteMapping("/remove-by-id/{id}")
//    public void removeById(@PathVariable Long id){
//        regionService.removeById(id);
//    }

    @ApiOperation(value = "保存或修改")
    @PostMapping(value = "/saveOrUpdate")
    public  void save(@RequestBody Region region){
        regionService.saveOrUpdate(region);
    }

    /**
     * 通过区域主键查询区域详情
     * @param id 区域主键
     * @return
     */
    @ApiOperation(value = "通过区域主键查询区域详情")
    @GetMapping(value = "/info-by-id")
    public Region infoById(@RequestParam("id") Long id){
        ValidatorHelpers.notEmpty(id, "区域编号不能为空");
        return regionService.infoById(id);
    }


    @ApiOperation(value = "通过车站名查询区域名")
    @GetMapping(value = "/getRegionByStation")
    public List<String> getRegionByStation(@RequestParam String stationName){
        return regionService.getRegionName(stationName);
    }

//    @ApiOperation(value = "通过车站名查询")
//    @GetMapping(value = "/selectByStation")
//    public IPage<Region> selectByStation(Page<Region> page, String stationName){
//        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("station_name", stationName);
//        return regionService.page(page, queryWrapper);
//    }

    @ApiOperation(value = "查询所有")
    @GetMapping(value = "/page")
    public IPage<Region> getPage(Page<Region> page,
                                 @RequestParam(required = false) String stationName,
                                 @RequestParam(required = false) String condition){
        return regionService.getPage(page, stationName, condition);
    }

}

